<?php
namespace Admin\Controller;
use Think\Controller;
class AuthController extends Controller {
    public function login(){
    	layout(false);
        $this->display();
    }
    public function do_login(){
        $rules = array(     
            array('username','require','用户名必须填写！'),
            array('password','require','密码必须填写！'),
        );
        $admin_model = M("admin");
        if (!$admin_model->validate($rules)->create()){    
             $this->error($admin_model->getError());
        }else{
        	$username = I('post.username');
        	$password = md5(I('post.password'));
        	if ($admin = M('admin')->where(array(
        		'username' => $username,
        		'password' => $password
        	))->find()) {
        		$_SESSION['admin_is_login'] = true;
        		$_SESSION['admin_name'] = $admin['username'];
        		$this->success('登陆成功！',U('admin/index/index'));
        	}else{
        		$this->error('账户名密码错误，请重新登录！','admin/auth/login');
        	}
        }
    }
    public function logout(){
        session_destroy();
        $this->redirect('admin/auth/login');
    }
}